﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SundStudent.ModelLayer;
using SundStudent.ControlLayer;

namespace SundStudent.GUILayer
{
    public partial class JournalForm : Form
    {
        private LektionsPatient selectedPatient;
        private PatientControler ctrlPatient = new PatientControler();
        public JournalForm(LektionsPatient patient)
        {
            InitializeComponent();
            selectedPatient = patient;
            labelSelected.Text = selectedPatient.Navn + " Stue:  " + selectedPatient.Stue.Stuenr + " Seng " + selectedPatient.Seng.Sengnr; 
            opdaterLisBox();
        }

        private void StatusAnkomst_Load(object sender, EventArgs e)
        {

        }
        private void opdaterLisBox()
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            listBox3.Items.Clear();
            listBox4.Items.Clear();
            listBox5.Items.Clear();
            listBox6.Items.Clear();
            listBox7.Items.Clear();
            listBox8.Items.Clear();
            listBox9.Items.Clear();
            listBox10.Items.Clear();
            listBox11.Items.Clear();
            listBox12.Items.Clear();
            listBox13.Items.Clear();


            List<Journal> journalList = ctrlPatient.HenAlleJournal(selectedPatient.Nr);
            if (journalList.Count > 0)
            {
                foreach (Journal journalObj in journalList)
                {
                    if (journalObj.Soegord.Equals("Kommunikation"))
                    {
                        listBox1.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month +"." +journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Viden og udvikling"))
                    {
                        listBox2.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Respiration og cirkulation"))
                    {
                        listBox3.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Ernæring"))
                    {
                        listBox4.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt  +" " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Udskillelse"))
                    {
                        listBox5.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt  +" " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Aktivitet"))
                    {
                        listBox6.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Hud og slimhinder"))
                    {
                        listBox7.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Smerter"))
                    {
                        listBox8.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Søvn og hvile"))
                    {
                        listBox9.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Seksualitet"))
                    {
                        listBox10.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Sanseindtryk"))
                    {
                        listBox11.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Psykosociale forhold"))
                    {
                        listBox12.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                    if (journalObj.Soegord.Equals("Åndelige/kulturelle/religiøse"))
                    {
                        listBox13.Items.Add(journalObj.Dato.Day + "." + journalObj.Dato.Month + "." + journalObj.Dato.Year + " " + journalObj.Vagt + " " + journalObj.Inti + " " + journalObj.PlanlagtHandling);
                    }
                }

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String dato = dateTimePicker1.Text.ToString();
           
            DateTime dato1 = new DateTime();
            dato1 = DateTime.Parse(dato);

            Console.WriteLine("dato : " + dato1);
            int dd = dato1.Day;
            int mm = dato1.Month;
            int yy = dato1.Year;
            DateTime dato2 = new DateTime(yy, mm, dd);
            Console.WriteLine("dato 2 : " + dato2);
            string init = textBox1.Text.ToString();
            string soegeord = comboBox1.SelectedItem.ToString();
            string beskrivelse = richTextBox1.Text.ToString();
            int indexvagt = comboBox2.SelectedIndex;
            String vagt = "";
            if( indexvagt == 0)
            {
                vagt = "DV";
            }
             if( indexvagt == 1)
            {
                vagt = "AV";
            }
            if( indexvagt == 2)
            {
                vagt = "NV";
            }
            Console.WriteLine("vagt " + vagt);

            int rc = ctrlPatient.GemJournal(dato2, selectedPatient.Nr, vagt, init, soegeord, beskrivelse, selectedPatient.IndDato);
            if (rc > 0)
            {
                label5.Text = "Oplysningerne er  registreret";
                opdaterLisBox();
                textBox1.Text = "";
                richTextBox1.Text = "";
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
    }
}

